package com.esun.rabbit2.viewer.mainact.optionact;

import com.esun.config.Language;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.ui.R;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;

/**
 * @Title: InviteAct.java
 * @Package com.esun.rabbit2.viewer.mainact.optionact
 * @Description:(短信/邮件邀请好友)
 * @author Billy qigs@500wan.com
 * @date 2011-5-24 下午04:03:35 copy right 深圳市易讯天空网络技术有限公司
 */
public class InviteAct extends Activity implements OnClickListener {
	private ImageButton btnBack;// 返回按钮
	private RelativeLayout relativeSMS;// 短信邀请按钮
	private RelativeLayout relativeMail;// 邮件邀请按钮

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.option_invite_act);

		init();// 初始化
	}

	/* 按钮事件监听 */
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.option_invite_act_relative_msg:// 短信邀请

			try {
				Uri uri = Uri.parse("smsto:");
				Intent itSMS = new Intent(Intent.ACTION_VIEW, uri);
				itSMS.putExtra("sms_body", getResources().getString(R.string.email_default_msg));
				startActivity(itSMS);
			} catch (Exception e) {
				Toast.makeText(InviteAct.this, Language.MSG_DOES_NOT_SUPPORT_SMS, Toast.LENGTH_SHORT).show();
			}
			break;
		case R.id.option_invite_act_relative_mail:// 邮件邀请

			try {
				Intent itEmail = new Intent(android.content.Intent.ACTION_SEND);
				itEmail.setType("plain/text");
				itEmail.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_default_subject));
				itEmail.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.email_default_msg));
				startActivity(itEmail);
			} catch (Exception e) {
				Toast.makeText(InviteAct.this, Language.MSG_PLEASE_CHECK_YOUR_MAILBOX, Toast.LENGTH_SHORT).show();
			}
			break;
		case R.id.optioninviteact_btn_back:// 返回
			InviteAct.this.finish();
			break;
		default:
			break;
		}
	}

	/* 初始化方法 */
	public void init() {
		btnBack = (ImageButton) findViewById(R.id.optioninviteact_btn_back);
		btnBack.setOnClickListener(this);

		relativeSMS = (RelativeLayout) findViewById(R.id.option_invite_act_relative_msg);
		relativeSMS.setOnClickListener(this);

		relativeMail = (RelativeLayout) findViewById(R.id.option_invite_act_relative_mail);
		relativeMail.setOnClickListener(this);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
	}
}
